import 'dart:io';

import 'package:asmore/library.dart';
import 'package:flutter/material.dart';

import '../util.dart';

class ArtworkScreen extends StatelessWidget {
  final ValueNotifier<Artwork?> work;

  const ArtworkScreen(this.work, {super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: NestedScrollView(
        headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
          return <Widget>[
            SliverAppBar(
              expandedHeight: 200.0,
              // floating: false,
              // pinned: true,
              flexibleSpace: FlexibleSpaceBar(
                // centerTitle: true,
                title: Text(work.value!.id),
                background: work.value!.cover != ""
                    ? Image.file(
                        File(work.value!.cover),
                        // 图片的URL
                        fit: BoxFit.cover,
                      )
                    : Image.asset(
                        "assets/images/cover.png",
                        // 图片的URL
                        fit: BoxFit.cover,
                      ),
              ),
              pinned: true,
              // 是否固定在顶部
              stretch: true,
              // 完全展开后是否可以继续拉伸
              backgroundColor: Colors.white,
              elevation: 4.0, // z坐标顺序
              // bottom: TabBar(
              //   tabs: [
              //     Tab(icon: Icon(Icons.directions_car)),
              //     Tab(icon: Icon(Icons.directions_transit))
              //   ],
              //   labelColor: Colors.blue,
              //   unselectedLabelColor: Colors.grey,
              //   indicatorColor: Colors.blue,
              //   onTap: (index) {
              //     /* Tab被点击时的回调 */
              //   },
              // ),
            ),
            SliverPadding(
              padding: EdgeInsets.all(6),
              sliver: SliverList.list(
                children: [
                  Text(
                    work.value!.title,
                    style: Theme.of(context).textTheme.titleMedium,
                  ),
                  Text(work.value!.maker_id,
                      style: Theme.of(context).textTheme.titleSmall),
                  SizedBox(
                    height: Theme.of(context).textTheme.titleSmall?.height,
                  ),
                  Row(
                    children: [
                      Text("评分:${work.value!.rate_average_2dp}"),
                      Text("评论:101"),
                      SizedBox(
                        width: Theme.of(context)
                            .textTheme
                            .labelLarge
                            ?.fontSize
                            ?.sign,
                      ),
                      Text("时长:${format(work.value!.getDuration())}"),
                      Text("链接"),
                    ],
                  ),
                  Row(
                    children: [
                      Text("${work.value!.price} JPY",
                          style: Theme.of(context)
                              .textTheme
                              .labelLarge
                              ?.apply(color: Colors.red)),
                      Text("销量:${work.value!.dl_count}",
                          style: Theme.of(context).textTheme.labelMedium),
                      Text("特性1",
                          style: Theme.of(context).textTheme.labelMedium),
                      Text("特性2",
                          style: Theme.of(context).textTheme.labelMedium),
                      Text(work.value!.age_category == 1 ? "全年龄" : "",
                          style: Theme.of(context)
                              .textTheme
                              .labelMedium!
                              .apply(color: Colors.green)),
                    ],
                  ),
                  SizedBox(
                    height: 4,
                  ),
                  Row(
                    children: [
                      OutlinedButton(onPressed: () {}, child: Text("Tag")),
                      SizedBox(
                        width: 4,
                      ),
                      OutlinedButton(onPressed: () {}, child: Text("Tag")),
                      SizedBox(
                        width: 4,
                      ),
                      OutlinedButton(onPressed: () {}, child: Text("Tag")),
                      SizedBox(
                        width: 4,
                      ),
                      OutlinedButton(onPressed: () {}, child: Text("Tag"))
                    ],
                  ),
                  SizedBox(
                    height: 6,
                  ),
                  Row(children: [
                    FilledButton.tonal(
                      onPressed: () {},
                      child: Text("CV"),
                    ),
                  ])
                ],
              ),
            ),
          ];
        },
        body: Container(
          margin: EdgeInsets.all(6),
          child: Card(
            child: Padding(
                padding: EdgeInsets.all(4), // 设置内边距
                child: ListView.builder(
                    itemCount: work.value!.tracks.length,
                    itemBuilder: (BuildContext context, int index) {
                      return ListTile(
                        title: Text(
                            '${index + 1} ${work.value!.tracks[index].name}'),
                        subtitle:
                            Text(format(work.value!.tracks[index].duration)),
                        onTap: () {},
                      );
                    })),
          ),
        ),
      ),
    );
  }
}
